<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        ul {
            list-style: none;
        }

        #newsBox {
            box-sizing: border-box;
            width: 300px;
            padding: 20px;
            border: 2px solid lightblue;
        }

        li {
            line-height: 35px;
            border-bottom: 1px dashed lightcoral;
            padding-left: 10px;
            cursor: pointer;
        }

        li:last-child {
            border-bottom: none;
        }

        /*     li:nth-child(even) {
            background-color: red;
        }

        li:nth-child(odd) {
            background-color: blue;
        }

        li:hover {
            background-color: skyblue;
        } */
    </style>

</head>

<body>

    <div class="box">
        <ul id="newsBox">
            <li>我是li-1</li>
            <li>我是li-2</li>
            <li>我是li-3</li>
            <li>我是li-4</li>
            <li>我是li-5</li>
        </ul>
    </div>
    <script>
        let newsBox = document.querySelector('#newsBox')
        let newsLists = document.querySelectorAll('li')
        console.log(newsLists);
        for (var i = 0; i < newsLists.length; i++) {
            newsLists[i].style.backgroundColor = (i % 2 !== 0 ? 'red' : 'blue')
     /*        if (i % 2 !== 0) {
                newsLists[i].style.backgroundColor = '#aaa'
            } else {
                newsLists[i].style.backgroundColor = '#ddd'
            }
       */  }

    </script>

</body>

</html>